﻿<UserControl x:Class="YouTubePlaylist.Views.Desktop"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:ContentControls="clr-namespace:Radovici.Ctrls.ContentControls;assembly=RadoviciCtrls" 
    xmlns:Panels="clr-namespace:Radovici.Ctrls.Panels;assembly=RadoviciCtrls"      
    xmlns:Views="clr-namespace:YouTubePlaylist.Views" 
    xmlns:SharedLibrary="clr-namespace:Radovici.SharedLibrary;assembly=RadoviciSharedLibrary"
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
    xmlns:Facebook="clr-namespace:Radovici.Ctrls.Facebook;assembly=RadoviciCtrls">
    <UserControl.Resources>
        <SharedLibrary:BooleanToVisibilityConverter x:Key="ToVisibilityConverter" />
        <ItemsPanelTemplate x:Key="WidgetPanelTemplate">
            <Controls:WrapPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
        <DataTemplate x:Key="WidgetDataTemplate">
            <ContentControls:Dragable IsDragPermanent="True">
                <ContentControls:Sizable>
                    <ContentControls:Widget Loaded="OnWidgetLoaded" Closed="OnWidgetClosed" 
                                            Title="{Binding Model.Title}"/>
                </ContentControls:Sizable>
            </ContentControls:Dragable>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="MenuItemPanelTemplate">
            <Panels:MacPanel/>
        </ItemsPanelTemplate>
        <DataTemplate x:Key="MenuItemDataTemplate">
            <ContentControls:MenuItem Margin="12" MouseLeftButtonUp="OnMenuItemClicked">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0" Text="{Binding Title}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    <Image Grid.Row="1" Source="{Binding Icon}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    <TextBlock Grid.Row="2" Text="{Binding Description}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                </Grid>
            </ContentControls:MenuItem>
        </DataTemplate>
    </UserControl.Resources>
    <Panels:DragableCanvas x:Name="DragableCanvas">
        <ContentControls:DropTarget TargetDataContext="{Binding Model}">
            <Grid x:Name="MainGrid">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="100"/>
                    <RowDefinition Height="28"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <!--<TextBlock Text="{Binding Model.Model.FacebookApi.User.Name}"/>
                    <Image Text="{Binding Model.Model.FacebookApi.User.Picture}"/>
                    <TextBlock Text="{Binding Model.Model.FacebookApi.User.Profile}"/>
                    <TextBlock Text="{Binding Model.Model.FacebookApi.User.Music}"/>-->
                <StackPanel Grid.RowSpan="3" Grid.ColumnSpan="2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2">
                    <!--<Facebook:FacebookConnect ApiKey="{Binding Model.Model.FacebookApiKey}" HorizontalAlignment="Left" Margin="0,0,0,2"/>-->
                    <Views:UserCtrl User="{Binding Model.Model.User}"/>
                    <ListBox ItemsSource="{Binding Model.Model.LogMessages}" BorderThickness="0" HorizontalAlignment="Left" Margin="0,0,0,2">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="24"/>
                                        <ColumnDefinition Width="*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="20"/>
                                        <RowDefinition Height="14"/>
                                    </Grid.RowDefinitions>
                                    <!--<Button HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.RowSpan="2" Click="OnFacebookUserClicked" Margin="0,0,4,0">
                                        <Image Source="{Binding FacebookUser.Picture}"/>
                                    </Button>-->
                                    <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center">
                                        <!--<ContentControls:Dropable SourceDataContext="{Binding FacebookUser}">
                                            <TextBlock Text="{Binding FacebookUser.Name}" MouseLeftButtonUp="OnFacebookUserNameClicked"/>
                                        </ContentControls:Dropable>-->
                                        <ContentControls:Dropable SourceDataContext="{Binding DropableContext}">
                                            <TextBlock Text="{Binding Display}" Margin="2,0,0,0"/>
                                        </ContentControls:Dropable>
                                    </StackPanel>
                                    <Grid Grid.Column="1" Grid.Row="1">
                                        <Viewbox VerticalAlignment="Center" HorizontalAlignment="Left">
                                            <TextBlock Text="{Binding ChangeDate}"/>
                                        </Viewbox>
                                        <!--<Viewbox VerticalAlignment="Center" HorizontalAlignment="Right" Visibility="{Binding CanPublish, Converter={StaticResource ToVisibilityConverter}}">
                                            <Button Click="OnPublishMessage" Cursor="Hand">
                                                <TextBlock Text="Publish"/>
                                            </Button>
                                        </Viewbox>-->
                                    </Grid>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>
                <StackPanel Grid.RowSpan="3" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="2">
                    <Views:PlaylistsCtrl PlaylistsModel="{Binding Model.MostRecentlyCreatedPlaylists}" Margin="0,0,0,2"/>
                    <Views:PlaylistsCtrl PlaylistsModel="{Binding Model.MostRecentlyUpdatedPlaylists}" Margin="0,0,0,2"/>
                </StackPanel>
                <Grid Grid.RowSpan="3" Grid.ColumnSpan="2" VerticalAlignment="Top" HorizontalAlignment="Center">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ContentControls:Sizable Grid.Row="0" MinWidth="320" MinHeight="180" Width="400">
                        <Views:YouTubePlayerCtrl PlaylistModel="{Binding Model.PlayingPlaylists.Current}"/>
                    </ContentControls:Sizable>
                    <ContentControls:Sizable Grid.Row="1" MinWidth="320" MinHeight="180">
                        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                            <Views:PlaylistsCtrl PlaylistsModel="{Binding Model.PlayingPlaylists}"/>
                        </ScrollViewer>
                    </ContentControls:Sizable>
                </Grid>
                <ItemsControl Grid.Row="0" Grid.ColumnSpan="2" ItemsSource="{Binding Model.WidgetModels}" ItemsPanel="{StaticResource WidgetPanelTemplate}" ItemTemplate="{StaticResource WidgetDataTemplate}" Margin="50"/>
                <ItemsControl Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Model.WidgetTemplates}" ItemsPanel="{StaticResource MenuItemPanelTemplate}" ItemTemplate="{StaticResource MenuItemDataTemplate}"/>
                <Grid Grid.Row="2" Grid.ColumnSpan="2" Margin="0,0,4,2" Opacity=".90">
                    <ProgressBar IsIndeterminate="{Binding Model.Model.IsCalculating}"/>
                    <TextBlock Text="{Binding Model.Model.Status}" VerticalAlignment="Center" Margin="4,0,0,0"/>
                </Grid>
            </Grid>
        </ContentControls:DropTarget>
    </Panels:DragableCanvas>
</UserControl>
